# __coding:utf-8__
from urllib.request import urlopen;
from urllib.request import urlretrieve
from bs4 import BeautifulSoup;
import csv;
import time;

html = urlopen('http://guba.eastmoney.com/list,300059.html');
bsObj = BeautifulSoup(html, 'lxml');
result = bsObj.find('div', {'id': 'articlelistnew'}).find_all('div');
lists = [];
for item in result:
    span = item.find_all('span');
    row = [];
    for s in span:
        row.append(s.text);
    lists.append(row);

title = lists.pop(0);
date = time.strftime('%Y-%m-%d', time.localtime());
handle = open('./lists' + date + '.csv', 'w+')
writer = csv.writer(handle);
writer.writerow(title);
for item in lists:
    writer.writerow(item);

print('写入成功')
